/**
 * 
 */
package com.hstypay.demo.example.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hstypay.cmq.queue.CmqQueueProducer;
import com.hstypay.cmq.topic.CmqTopicProducer;
import com.hstypay.demo.dto.HsUserDTO;
import com.hstypay.demo.facade.HsUserService;
import com.hstypay.framework.web.controller.BaseController;
import com.hstypay.framework.web.dto.Result;

/**
 * @author admin
 *
 */
@RestController
@RequestMapping("/example")
public class ExampleController extends BaseController{
	@Resource
	private HsUserService hsUserService;
	@Resource(name="hstypayDemoQueueProducer")
	private CmqQueueProducer<HsUserDTO> cmqQueueProducer;
	@Resource(name = "hstypayDemoTopicProducer")
	private CmqTopicProducer<HsUserDTO> cmqTopicProducer;
	
	@RequestMapping("/query/user")
	public HsUserDTO queryUser(@RequestParam("userId")Long userId){
		return hsUserService.queryUserById(userId);
	}
	
	@RequestMapping("/queue")
	public Result queue(@RequestParam("userId")Long userId){
		HsUserDTO hsUserDTO = hsUserService.queryUserById(userId);
		String resultMsg = cmqQueueProducer.convertAndSend(hsUserDTO, 5);
		logger.debug("CMQ消息发送返回结果：{}", resultMsg);
		return Result.ok();
	}
	
	@RequestMapping("/topic")
	public Result topic(@RequestParam("userId")Long userId){
		HsUserDTO hsUserDTO = hsUserService.queryUserById(userId);
		String resultMsg = cmqTopicProducer.convertAndPublish(hsUserDTO);
		logger.debug("CMQ消息发送返回结果：{}", resultMsg);
		return Result.ok();
	}
	
	@RequestMapping("/topic/bind")
	public Result topicBind(@RequestParam("userId")Long userId, @RequestParam(value="bindingKey", defaultValue="demo")String bindingKey){
		HsUserDTO hsUserDTO = hsUserService.queryUserById(userId);
		String resultMsg = cmqTopicProducer.convertAndPublish(hsUserDTO, bindingKey);
		logger.debug("CMQ消息发送返回结果：{}", resultMsg);
		return Result.ok();
	}
}
